package com.test.shop.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @date 2022/1/9 -11:03
 */
@Configuration
public class MyRedissonConfig {

    /**
     * 所有对redis的操作都是通过redissonClient
     * @return
     * destroyMethod = "shutdown" 表示是销毁方法，即服务调用停止后会销毁
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient RedissonClient () throws IOException {
        Config config = new Config();
        // 设置单集群模式，也可以根据需求设置多集群模式

        config.useSingleServer().
                setAddress("redis://192.168.56.10:6379");
//        config.useClusterServers().addNodeAddress("192.168.56.10:6379","192.168.56.10:6379","192.168.56.10:6379");
        return Redisson.create(config);
    }
}
